/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */

// 依次找到一对零和非零的，转换位置。
var moveZeroes = function (nums) {
    let i = 0;
    let len = nums.length;
    while (i < len) {
        if (nums[i] === 0) {
            let j = i + 1;
            while (j < len) {
                if (nums[j] === 0) {
                    j++;
                } else {
                    [nums[i], nums[j]] = [nums[j], nums[i]];
                    break;
                }
            }
        }
        i++;
    }
};

// 同个思路，一次for循环，更巧妙
var moveZeroes = function (nums) {
    if (nums === null) {
        return;
    }
    let j = 0;
    let len = nums.length;
    for (let i = 0; i < len; i++) {
        if (nums[i] != 0) {
            [nums[i], nums[j]] = [nums[j], nums[i]];
            j++;
        }
    }
};